<!-- 设备参数 -->
<template>
  <div>
    <el-row style="background: #fff; margin-bottom: 32px">
      <div class="content parameType" style="width: 800px">
        <div class="certification top"  style="width: 100%">
          <!-- <div class="toptitle">
            <div class="title">设备参数</div>
          </div> -->
          <div class="btn topSubmitBtn" style="display:flex;justify-content:flex-end;margin-bottom:10px;">
            <el-button type="primary" @click="SetExtraEMailCfg(emailForm)">保存设置</el-button>
          </div>
          <el-form label-width="160px">
            <el-col :xs="24" :sm="24" :lg="24">
              <el-form-item label="搜索引擎:">
                <el-select v-model="emailForm.SearchEngine" multiple  style="width:300px">
                  <el-option value='www.bing.com' label='bing'></el-option>
                  <el-option value='www.google.com' label='google'></el-option>
                  <el-option value='www.baidu.com' label='baidu'></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="24">
              <el-form-item label="并发进程数:">
                <!-- <el-input v-model.number="emailForm.ProcNumber"  oninput ="value=value.replace(/[^0-9]/g,'')" style="width:300px" maxlength="9"></el-input> -->
                <el-select v-model="emailForm.ProcNumber"  style="width:300px">
                  <el-option :value='1' label='1'></el-option>
                  <el-option :value='2' label='2'></el-option>
                  <el-option :value='3' label='3'></el-option>
                  <el-option :value='4' label='4'></el-option>
                  <el-option :value='5' label='5'></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="24">
              <el-form-item label="挖掘深度:">
                <el-input v-model.number="emailForm.Deep"  oninput ="value=value.replace(/[^0-9]/g,'')" style="width:300px" maxlength="9"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="24">
              <el-form-item label="单次挖掘最大邮件数量:">
                <el-input v-model.number="emailForm.MaxMailCount"  oninput ="value=value.replace(/[^0-9]/g,'')" style="width:300px" maxlength="9"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="24">
              <el-form-item label="挖掘任务执行超时时长:">
                <el-input v-model="emailForm.ExecTimeout"  oninput ="value=value.replace(/[^0-9]/g,'')" style="width:300px" maxlength="9">
                  <span slot="append">分钟</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="24">
              <el-form-item label="启用代理搜索机制:">
                <el-radio-group  v-model="emailForm.IsProxy">
                  <el-radio :label=1>启用</el-radio>
                  <el-radio :label=0>禁用</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <!-- <el-col :xs="24" :sm="24" :lg="24">
              <el-button type="primary" @click="SetExtraEMailCfg(emailForm)"  style="margin-left:360px">保存设置</el-button>
            </el-col> -->
          </el-form>
        </div>
      </div>
    </el-row>
  </div>
</template>
<script>
import { connrequest } from '@/api/firstPage'
export default {
data() {
  return {
    emailForm: {},
  }
},
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.GetExtraEMailCfg()
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {
  },
  methods: {
    async GetExtraEMailCfg(){
      const res = await connrequest('GetExtraEMailCfg')
      res.Data.ExecTimeout = res.Data.ExecTimeout / 60
      this.emailForm = res.Data
    },
    async SetExtraEMailCfg(){
      let SendInterval = /^[0-9]*$/ 
      if(this.emailForm.SearchEngine.length === 0) {
        this.$message.error('请至少选择一个搜索引擎')
      }else if(!this.emailForm.ProcNumber){
        this.$message.error('并发进程数不能为空')
      }else if(!this.emailForm.Deep){
        this.$message.error('挖掘深度不能为空')
      }else if(!this.emailForm.MaxMailCount){
        this.$message.error('单次挖掘最大邮件数量不能为空')
      }else if(!this.emailForm.ExecTimeout){
        this.$message.error('挖掘任务执行超时时长不能为空')
      }else if(!SendInterval.test(this.emailForm.ProcNumber)){
        this.$message.error('开发进程数只能为数字')
      }else if(!SendInterval.test(this.emailForm.Deep)){
        this.$message.error('挖掘深度只能为数字')
      }else if(!SendInterval.test(this.emailForm.MaxMailCount)){
        this.$message.error('单次挖掘最大邮件数量只能为数字')
      }else if(!SendInterval.test(this.emailForm.ExecTimeout)){
        this.$message.error('挖掘任务执行超时时长只能为数字')
      }else{
        let ExecTimeout = this.emailForm.ExecTimeout * 60 //转为秒数
        const data = {
          Data:{
            ...this.emailForm,
            ExecTimeout
          }
        }
        const res = await connrequest('SetExtraEMailCfg', data)
        if(res.Status.StatusCode === 0){
          this.$message.success('保存成功')
          this.GetExtraEMailCfg()
        }
      }
    },
  }
}
</script>
<style lang="scss" scoped>
/* @import url(); 引入css类 */
@import "~@/styles/variables.scss";
.parameType .title{
  border: none !important;
}
.content {
  margin-top: 0;
  width: 800px;
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  .title{
    margin-bottom: 10px;
  }
  ::v-deep .certification{
    .el-form-item{
      margin-bottom: 10px;
    }
  }
}
</style>